<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!--360浏览器优先以webkit内核解析-->


    <title> - 主页示例</title>

    <link rel="shortcut icon" href="../../src/main/resources/templates/admin/favicon.ico"> <link href="../../src/main/resources/templates/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../../src/main/resources/templates/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="../../src/main/resources/templates/static/admin/css/animate.css" rel="stylesheet">
    <link href="../../src/main/resources/templates/static/admin/css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        
			<div class="row">
			    <div class="col-sm-12">
			        <div class="ibox float-e-margins center">
			            
			            <div class="mytab">
							<table id="mytab" class="table table-hover"></table>
			            </div>

			        </div>
			    </div>
        </div>
	</div>
</body>
	
	<!-- 全局js -->
	
	<script src="../../src/main/resources/templates/static/admin/js/jquery.min.js?v=2.1.4"></script>
	<script src="../../src/main/resources/templates/static/admin/js/bootstrap.min.js?v=3.3.6"></script>
	<script src="../../src/main/resources/templates/static/admin/js/plugins/footable/footable.all.min.js"></script>
		
	<!-- 自定义js -->
	<script src="../../src/main/resources/templates/static/admin/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
	<script src="../../src/main/resources/templates/static/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
	<script src="../../src/main/resources/templates/static/admin/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
	 
	 
	<script src="../../src/main/resources/templates/static/admin/js/content.js?v=1.0.0"></script>
	<script>
	$(function() {
	var flag = 0;
	var id = null;
	var name = null;
	var startTime = null;
	var endTime = null;
	    $('#mytab').bootstrapTable({
	        method : 'get',
	        // contentType: "application/x-www-form-urlencoded",//当请求方法为post的时候,必须要有！！！！
	        url : "http://test.wslhome.top/admin/getActivityAll/v1",
			dataType: "json",
	        striped : true, // 是否显示行间隔色
	        pageNumber : 1, // 初始化加载第一页
	        pagination : true,// 是否分页
	        sidePagination : 'server',// server:服务器端分页|client：前端分页
	        pageSize : 10,
	        pageList : [ 5, 10, 20, 30 ],
	        showRefresh : true,//刷新按钮
			
	        queryParams : queryParams,
			 responseHandler: returnFormat,
	      columns : [ {
	          title : 'id',
	          field : 'id',
	          sortable : true
	      }, {
	          title : '商品名',
	          field : 'goodsName',
	          sortable : true
	      }, {
	          title : '开始时间',
	          field : 'startTime',
	      }, {
	          title : '结束时间',
	          field : 'endTime',
	      	sortable : true
	      } , {
	          title : '创建时间',
	          field : 'creatTime',
	      	sortable : true
	      }, {
	          title : '商品列表',
	          field : 'skuList',
	      	formatter : function(value,row, index){
	      	        
					for (sku in row.skuList
					){
						console.log(sku);
					}
					
					return row.id;
					}
	      },{
              title:'操作',
              field:'Button',
              align:'center',
              formatter:AddFunctionAlty//添加按钮
           
	      }] 
	    })
	 
	 /**
	  * formatter : function(value,records, index){   //主要配置在这里
				console.log(records.id)
	                            return row.records.id;
	    }*/
		
		function queryParams(params) {
		    var temp = {
				status : flag,
				id: id,
				name: name,
				startTime: startTime,
				endTime:endTime
		    };
		    return temp;
		}
		
		function returnFormat(res) {
		    console.log(res);
		    return {
				"rows":res.data.records,
				"total": res.data.total
				}
		}
					   
		//列表行‘操作’按钮
		  function AddFunctionAlty(value, row, index) {
		   return '<button id="TableView" type="button" class="btn btn-default">查看</button>'
		
		}
		
	    // 定义删除、更新操作
	    function option(value, row, index) {
	        var htm = '<button id="delUser" userId='
	                + value
	                + ' onclick="delUser(this)">删除</button><button id="dupUser" onclick="updUser('
	                + value + ')">修改</button>'
	        return htm;
	    }
	 
	    // 查询按钮事件
	    $('#search_btn').click(function() {
	        $('#mytab').bootstrapTable('refresh', {
	            url : path + '/user/list'
	        });
	    })
	 
	    // 添加用户
	    $("#userAdd").on("click", function() {
	        layer.open({
	            type : 2,
	            title : '添加用户',
	            area : [ '500px', '440px' ],
	            fix : false, // �
	            content : path + '/user/pageAdd',
	            end : function() {
	                $("#mytab").bootstrapTable('refresh', {
	                    url : path + "/user/list"
	                });
	            }
	        });
	    });
	 
	})
	 
	// 删除用户
	function delUser(dom) {
	   
	    var mymessage = confirm("确认删除嘛？");
	    if (mymessage == true) {
	        $.ajax({
	            url : path + '/user/' + $(dom).attr("userId"),
	            type : 'delete',
	            success : function(data) {
	                $(dom).parent().parent().hide();
	            },
	            error : function(data){
	                alert("服务器繁忙")
	            }
	        });
	    }
	}
	 
	// 编辑用户
	function updUser(id) {
	    layer.open({
	        type : 2,
	        title : '编辑用户',
	        area : [ '500px', '440px' ],
	        fix : false, // �
	        content : path + '/user/pageUpd/' + id,
	        end : function() {
	            $("#mytab").bootstrapTable('refresh', {
	                url : path + "/user/list"
	            });
	        }
	    });
	}
	 
	// 获取项目路径
	function getContextPath() {
	    var currentPath = window.document.location.href;
	    var pathName = window.document.location.pathname;
	    var pos = currentPath.indexOf(pathName);
	    var localhostPath = currentPath.substring(0, pos);
	    var projectName = pathName
	            .substring(0, pathName.substr(1).indexOf('/') + 1);
	    return (localhostPath + projectName);
	}

	 
	</script>
	
</html>		